﻿@using System

@page "/Console Monsters"

<PageTitle>Console Monsters</PageTitle>

<h1>Console&nbsp;Monsters</h1>

<a href="https://github.com/dotnet/dotnet-console-games/tree/main/Projects/Console%20Monsters" alt="Go To Readme">
	<img title="Go To Readme" alt="Go To Readme" src="https://raw.githubusercontent.com/dotnet/dotnet-console-games/main/.github/resources/readme-black.svg">
</a>

<div class="alert alert-warning" role="alert" style="margin-top: 0.5rem;">
	&#9888; WARNING! This game is still a work in progress. It is unfinished and still being developed. Also, this web version of the game may not be up to date with the console version due to the currently manual porting process.
</div>

<div class="console-window text-center my-3" @onkeydown="@Console.OnKeyDown" tabindex="0">
	<div class="d-inline-block bg-dark text-light border p-2 text-start shadow padding-0">
		<pre class="console">
		<code>@Console.State</code>
		</pre>
	</div>
	<div>
		<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.UpArrow)   ">↑</button>
		<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.DownArrow) ">↓</button>
		<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.LeftArrow) ">←</button>
		<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.RightArrow)">→</button>
		<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.E)         ">E</button>
		<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.B)         ">B</button>
		<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.Enter)     ">enter</button>
		<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.Escape)    ">escape</button>
	</div>
</div>

<div class="alert alert-secondary" role="alert">
	&#9000; Keyboard input is supported if you <strong>click</strong> on the game.
</div>

<div class="alert alert-secondary" role="alert">
	&#8635; You can restart the game by <strong>refreshing</strong> the page.
</div>

@code
{
	Games.Console_Monsters.Console_Monsters Game;
	BlazorConsole Console;

	public Console_Monsters()
	{
		Game = new();
		Console = Game.Console;
		Console.WindowWidth = 150;
		Console.WindowHeight = 50;
		Console.TriggerRefresh = StateHasChanged;
	}

	protected override void OnInitialized() => InvokeAsync(Game.Run);
}
